<?php

namespace App\Http\Controllers\Backend\Product;

use App\ConstDir\ErrorConst;
use App\Http\Controllers\Backend\BaseController;
use Illuminate\Http\Request;
use App\Repository\Repositories\Interfaces\ProductAttributesRepository;

 
class ProductAttributesController extends BaseController
{
    
    protected $product_attrs_repo;

    public function __construct(ProductAttributesRepository $product_attrs_repo)
    {
        $this->product_attrs_repo = $product_attrs_repo;
    }

    public function index(Request $request){
        $type = $request->get('type', 'page');
        if($type == 'page'){
            $skus = $this->product_attrs_repo->paginate($this->perPage);
            return $this->success(ErrorConst::SUCCESS_CODE_MSG, $skus, true);
        }elseif($type == 'all'){
            $skus = $this->product_attrs_repo->all();
            return $this->success(ErrorConst::SUCCESS_CODE_MSG, $skus['data']);
        }
    }

    public function show($prodcut_attrs_id){
        $product_info = $this->product_attrs_repo->find($prodcut_attrs_id);
        
        return $this->success(ErrorConst::SUCCESS_CODE, $product_info['data']);
    }
    
    public function getByProductId($product_id){
        $product_info = $this->product_attrs_repo->whereFirst(['product_id'=>$product_id]);
        return $this->success(ErrorConst::SUCCESS_CODE, $product_info['data']);
    }
 
}
